package com.shuo.dsa.niuke;

/**
 * 从1 到 n 中1出现的次数
 *          思路1: 全转为str拼在一起, 遍历有几个'1'
 */
public class CountNumOf1 {
    /**
     * 很傻逼的暴力算法
     */
    public int NumberOf1Between1AndN_Solution(int n) {
        int ret = 0;
        StringBuilder str = new StringBuilder();
        for (int i = 1; i <= n; i++) {
            str.append(i);
        }
        char[] chars = str.toString().toCharArray();
        for (char aChar : chars) {
            if (aChar == '1')
                ret++;
        }
        return ret;
    }
}
